package com.xja.service.impl;/**
 * @className: UserServiceImpl
 * @description: TODO 类描述
 * @author: wkx
 * @date: 2022/4/17
 **/

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xja.mapper.UserMapper;
import com.xja.pojo.BlogUsers;
import com.xja.pojo.FocusInfo;
import com.xja.service.UserService;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName : UserServiceImpl  //类名

 * @Author : Lenovo //作者
 * @Date: 2022/4/17  10:46
 */
@Service
public class UserServiceImpl implements UserService {
    private Logger logger= LoggerFactory.getLogger(UserServiceImpl.class);
    @Autowired
    private UserMapper userMapper;
    @Transactional(readOnly = true)
    @Override
    public BlogUsers login(BlogUsers blogUsers) {
        return userMapper.login(blogUsers);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void register(BlogUsers blogUsers) {
        userMapper.register(blogUsers);
    }

    @Transactional(readOnly = true)
    @Override
    public BlogUsers selectUserById(Integer bloguid) {
        BlogUsers blogUsers = userMapper.selectUserById(bloguid);
        logger.info("用户业务层："+blogUsers);
        return blogUsers;
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int attention(FocusInfo focusInfo) {
        return userMapper.attention(focusInfo);
    }



    @Transactional(readOnly = true)
    @Override
    public List<FocusInfo> selectFocusByUid(Integer uid) {
        return userMapper.selectFocusByUid(uid);
    }
    @Transactional(readOnly = true)
    @Override
    public Integer selectSourceCountByUid(Integer uid) {
        return userMapper.selectSourceCountByUid(uid);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public boolean deleteFocusInfo(Integer targetUid, Integer sourceUid) {
        int row = userMapper.deleteFocusInfo(targetUid,sourceUid);
        if (row>0){
            return true;
        }
        return false;
    }

    @Override
    public List<FocusInfo> selectSourceById(Integer uid) {
        return userMapper.selectSourceById(uid);
    }

    @Transactional(readOnly = true)
    @Override
    public List<BlogUsers> getUser(BlogUsers users, Integer page) {
        PageHelper.startPage(page,5);
        List<BlogUsers> blogUsers = userMapper.selectUser(users);
        PageInfo<BlogUsers> pageInfo = new PageInfo<>(blogUsers);
        pageInfo.setPageNum(page);
        return pageInfo.getList();
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void activeUser(Integer uid) {
        userMapper.updateActiveUser(uid);
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void freezeUser(Integer uid) {
        userMapper.updateFreezeUser(uid);
    }


}
